/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.apache.passport.service.plugins  
 */
package com.apache.passport.service.plugins;

import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.cache.util.Validator;
import com.apache.database.db.IDao;
import com.apache.database.model.MethodParam;
import com.apache.passport.entity.UctUser;

/**
 * description:  验证用户名是否唯一
 * @author Hou Dayu 创建时间：2014-12-22  
 * @Copyright(c)2014:
 */
public class ChkEnamePlugin implements PluginConnector {
	protected IDao uctUserDao;

	public void setUctUserDao(IDao uctUserDao) {
		this.uctUserDao = uctUserDao;
	}

	/**
	 * TODO 简单描述该方法的实现功能（可选）.  
	 * @see com.apache.api.manager.PluginConnector#execute(com.apache.api.vo.ParamsVo)  
	 */
	@Override
	public Object execute(ParamsVo paramsvo) throws Exception {
		ResultEntity result = new ResultEntity();
		result.setResult("true");
		result.setEntity("F");
		result.setMessage("数据查询异常");
		String userEname = (String) paramsvo.getParams("userEname");
		if (Validator.isNull(userEname)) {
			result.setEntity("F");
			result.setMessage("用户名不能为空");
			return result;
		}

		UctUser uctUser = (UctUser) getInfoByEname(userEname);
		if (Validator.isEmpty(uctUser)) {
			result.setEntity("T");
			result.setMessage("用户名不存在");
			return result;
		} else {
			result.setMessage("用户名已存在");
		}
		return result;
	}

	/**
	 * description:  根据ename查询用户信息
	 * @param vo
	 * @return  
	 * @author Hou Dayu 
	 * @update 2014-12-19
	 */
	public Object getInfoByEname(String userEname) {
		String sql = uctUserDao.getSql(3);
		MethodParam param = new MethodParam("ByUserEname", "", sql, "com.apache.passport.entity.UctUser");
		param.setParams("userEname", userEname);
		return uctUserDao.selectSingle(param);
	}

}
